package com.finance.cooperate.data.feature;

/**
 * @ClassName FeatureDefinition
 * @Description 特征定义
 * @Author shen
 * @Date 2023/8/10 21:24
 * @Modify ...
 */
public enum FeatureDefinition {

    // ************************ PublicReader ************************
    f_public_uid("用户id", "f_public_uid", false, true),
    f_public_loan_num("贷款次数", "f_public_loan_num", false, true),
    f_public_last_submit_time("最后近件时间", "f_public_last_submit_time", false, true),


    // ************************ AppReader ************************
    f_app_data("app数据", "f_app_data", false, true),


    // ************************ ScrapyReader ************************
    f_scrapy_data("爬虫数据", "f_scrapy_data", false, true),


    // ************************ SmsReader ************************
    f_sms_data("短信数据", "f_sms_data", false, true),


    NULL("", "", false, false);


    private String desc;
    private String value;
    private boolean isOneHot;
    private boolean status;

    FeatureDefinition(String desc, String value, boolean isOneHot, boolean status) {
        this.desc = desc;
        this.value = value;
        this.isOneHot = isOneHot;
        this.status = status;
    }

    public String getValue() {
        return this.value;
    }

    public String getDesc() {
        return this.desc;
    }

    public boolean getIsOneHot() {
        return this.isOneHot;
    }

    public boolean getStatus() {
        return this.status;
    }

    public static boolean getStatus(String value) {
        FeatureDefinition[] featureDefinitions = values();
        for (FeatureDefinition featureDefinition : featureDefinitions) {
            if (featureDefinition.getValue().equals(value)) {
                return featureDefinition.getStatus();
            }
        }
        return false;
    }

    public static String getDesc(String value) {
        FeatureDefinition[] featureDefinitions = values();
        for (FeatureDefinition featureDefinition : featureDefinitions) {
            if (featureDefinition.getValue().equals(value)) {
                return featureDefinition.getDesc();
            }
        }
        return null;
    }


    public static Boolean contains(String value){
        for(FeatureDefinition featureDefinition : FeatureDefinition.values()){
            if(featureDefinition.getValue().equals(value)){
                return true;
            }
        }
        return false;
    }


    public static boolean isOneHot(String value) {

        if (!contains(value) || value.endsWith("_")) {
            // 可能是热编码子类型

            FeatureDefinition[] featureDefinitions = values();
            for (FeatureDefinition featureDefinition : featureDefinitions) {

                // 之前判断不对，如果后面有多个"__"就不对了

                String v = featureDefinition.getValue();
                if (v.endsWith("_")) {

                    if (value.length() >= v.length()) {

                        String valueTemp = value.substring(0, v.length());

                        if (v.equals(valueTemp)) {
                            return featureDefinition.getIsOneHot();
                        }

                    }

                }

            }

        }

        return false;
    }


}
